package com.tjmntv.tj.myapplication.demo7

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.tjmntv.tj.myapplication.R
import kotlinx.android.synthetic.main.activity_kotlin_demo07.*

class KotlinDemo07 : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_kotlin_demo07)
        mainViewPager.apply {
            adapter = object : FragmentStateAdapter(this@KotlinDemo07) {
                override fun getItemCount() = 3
                override fun createFragment(position: Int) = when (position) {
                    1 -> VideoFragment()
                    else -> FooFragment()
                }
            }
            setCurrentItem(1, false)
        }
        TabLayoutMediator(tablayout, mainViewPager) { tab: TabLayout.Tab, i: Int ->
            tab.text = when (i) {
                1 -> "video"
                else -> "Foo"
            }
        }.attach()
    }
}